unit MedKubLent;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Tools,
  GForm, cxGraphics, cxPropertiesStore, dxBarExtItems, dxBar,
  cxClasses, ActnList, dxStatusBar, cxControls, cxPC, cxStyles, cxCustomData,
  cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, cxGridLevel,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGridCustomView,
  cxGrid, cxNavigator, cxDBNavigator, cxContainer, cxGroupBox, cxCalc,
  cxLookAndFeelPainters, impexp, cxGridCustomPopupMenu, cxGridPopupMenu;

type
  TfMedKubLent = class(TGamaForm)
    tsSarasas: TcxTabSheet;
    dbgSarasas: TcxGrid;
    dbgSarasasDBTableView: TcxGridDBTableView;
    dbgSarasasLevel1: TcxGridLevel;
    dbgSarasasDBTableViewgalas: TcxGridDBColumn;
    dbgSarasasDBTableViewilgis: TcxGridDBColumn;
    dbgSarasasDBTableViewturis: TcxGridDBColumn;
    cxGroupBox1: TcxGroupBox;
    dbnNav: TcxDBNavigator;
    cxGridPopupMenu1: TcxGridPopupMenu;
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure GmiImportasClick(Sender: TObject);
  private
    { Private declarations }
    m_arImportas: boolean;

    procedure LentelesOn;
    procedure LentelesOff;
    //
    procedure MainBeforeInserOrEdit(DataSet: TDataSet);
    procedure MainBeforePost(DataSet: TDataSet);
    procedure MainAfterPostOrDelete(DataSet: TDataSet);
    procedure MainAfterPostOrDeleteOrCancel(DataSet: TDataSet);
    procedure MainPostError(DataSet: TDataSet;
                E: EDatabaseError; var Action: TDataAction);
    procedure MainNewRecord(DataSet: TDataSet);
  public
    { Public declarations }
    procedure RefreshTables; override;
  end;

var
  fMedKubLent: TfMedKubLent;

implementation

{$R *.dfm}

uses
  bendri, med_dm;

procedure TfMedKubLent.LentelesOn;
begin
  with dmMed do begin
    tbMedRastKub.BeforeInsert  := self.MainBeforeInserOrEdit;
    tbMedRastKub.BeforeEdit    := self.MainBeforeInserOrEdit;
    tbMedRastKub.BeforePost    := self.MainBeforePost;
    tbMedRastKub.AfterPost     := self.MainAfterPostOrDelete;
    tbMedRastKub.AfterDelete   := self.MainAfterPostOrDelete;
    tbMedRastKub.AfterCancel   := self.MainAfterPostOrDeleteOrCancel;
    //tbMedRastKub.OnPostError   := self.MainPostError;
    tbMedRastKub.OnNewRecord   := self.MainNewRecord;
  end;
end;

procedure TfMedKubLent.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  LentelesOff;
end;

procedure TfMedKubLent.FormShow(Sender: TObject);
begin
  inherited;
  LentelesOn;
end;

procedure TfMedKubLent.GmiImportasClick(Sender: TObject);
begin
  try
    LentelesOff;
    m_arImportas := true;
    fImpExp.DataSet := dmMed.tbMedRastKub;
    dmMed.tbMedRastKub.DisableControls;
    //fImpExp.BeforeStart := ImportBeforeStart;
    //fImpExp.AfterEnd := ImportAfterEnd;
    //dmVagonai.tbVStotys.OnNewRecord := self.StotysNewRecord;
    //fImpExp.BeforeInsert := ImportBeforeInsert;
    fImpExp.ImEx := importas;
    fImpExp.IniFileName := 'ismatavimai.ini';
    if fImpExp.ShowModal(DokTipas) <> mrYes then Exit;
  finally
    m_arImportas := false;
    dmBendras.ApplyUpdatesAfterPostOrDelete( dmMed.tbMedRastKub );
    dmMed.tbMedRastKub.Refresh;
    dmMed.tbMedRastKub.EnableControls;
    bRefreshTables := true;
    //dmVagonai.tbVVagonaiS.Refresh;
    LentelesOn;
  end;
end;

procedure TfMedKubLent.LentelesOff;
begin
  with dmMed do begin
    tbMedRastKub.BeforeInsert  := nil;
    tbMedRastKub.BeforeEdit    := nil;
    tbMedRastKub.BeforePost    := nil;
    tbMedRastKub.AfterPost     := nil;
    tbMedRastKub.AfterDelete   := nil;
    tbMedRastKub.AfterCancel   := nil;
    //tbMedRastKub.OnPostError   := nil;
    tbMedRastKub.OnNewRecord   := nil;
  end;
end;

procedure TfMedKubLent.MainBeforePost(DataSet: TDataSet);
begin
  //MessageText := '';
  //dmBendras.RandomIDBeforePost(DataSet);
end;

procedure TfMedKubLent.MainPostError(DataSet: TDataSet;
                E: EDatabaseError; var Action: TDataAction);
begin
  //dmBendras.RandomIDPostError(DataSet, E, Action);
end;

procedure TfMedKubLent.MainNewRecord(DataSet: TDataSet);
begin
  //
end;

procedure TfMedKubLent.MainAfterPostOrDelete(DataSet: TDataSet);
begin
  dmBendras.ApplyUpdatesAfterPostOrDelete(DataSet);
  MainAfterPostOrDeleteOrCancel(DataSet);
  bRefreshTables := true;
end;

procedure TfMedKubLent.MainAfterPostOrDeleteOrCancel(DataSet: TDataSet);
begin
  SetControlsEditColor( DataSet, GamaPageControl, false );
end;

procedure TfMedKubLent.MainBeforeInserOrEdit(DataSet: TDataSet);
begin
  SetControlsEditColor( DataSet, GamaPageControl, true);
end;

procedure TfMedKubLent.RefreshTables;
begin
  if bRefreshTables then begin
    bRefreshTables := false;
    dmMed.tbMedRastStoris.Refresh;
    dmMed.tbMedRastIlgis.Refresh;
    //dmAlga.tbIssilavLookup.Refresh;
  end
end;
end.
